package com.ruoyi.web.controller.eamp;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.eamp.domain.EampMeetingPeople;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.eamp.domain.EampMeetingRoom;
import com.ruoyi.eamp.service.IEampMeetingRoomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议室表Controller
 * 
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/eamp/meeting_room")
public class EampMeetingRoomController extends BaseController
{
    @Autowired
    private IEampMeetingRoomService eampMeetingRoomService;

    /**
     * 查询会议室表列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:meeting_room:list')")
    @GetMapping("/list")
    public TableDataInfo list(EampMeetingRoom eampMeetingRoom)
    {
        startPage();

        List<EampMeetingRoom> list = eampMeetingRoomService.selectEampMeetingRoomList(eampMeetingRoom);
        return getDataTable(list);
    }

    /**
     * 导出会议室表列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:meeting_room:export')")
    @Log(title = "会议室表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EampMeetingRoom eampMeetingRoom)
    {
        List<EampMeetingRoom> list = eampMeetingRoomService.selectEampMeetingRoomList(eampMeetingRoom);
        ExcelUtil<EampMeetingRoom> util = new ExcelUtil<EampMeetingRoom>(EampMeetingRoom.class);
        util.exportExcel(response, list, "会议室表数据");
    }

    /**
     * 获取会议室表详细信息
     */
    @PreAuthorize("@ss.hasPermi('eamp:meeting_room:query')")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return success(eampMeetingRoomService.selectEampMeetingRoomByRoomId(roomId));
    }

    /**
     * 新增会议室表
     */
    @PreAuthorize("@ss.hasPermi('eamp:meeting_room:add')")
    @Log(title = "会议室表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EampMeetingRoom eampMeetingRoom)
    {
        eampMeetingRoom.setCreatTime(new Date());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        eampMeetingRoom.setCreatBy(user.getUserName());
        int i = eampMeetingRoomService.insertEampMeetingRoom(eampMeetingRoom);
        System.out.println(eampMeetingRoom);
        return toAjax(i);
    }

    /**
     * 修改会议室表
     */
    @PreAuthorize("@ss.hasPermi('eamp:meeting_room:edit')")
    @Log(title = "会议室表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EampMeetingRoom eampMeetingRoom)
    {
        return toAjax(eampMeetingRoomService.updateEampMeetingRoom(eampMeetingRoom));
    }

    /**
     * 删除会议室表
     */
    @PreAuthorize("@ss.hasPermi('eamp:meeting_room:remove')")
    @Log(title = "会议室表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(eampMeetingRoomService.deleteEampMeetingRoomByRoomIds(roomIds));
    }
    @PostMapping("/roomId")
    public TableDataInfo getroomIdList(){
        List<EampMeetingRoom> list1 =eampMeetingRoomService.getroomIdList();

        TableDataInfo result = new TableDataInfo();
        result.setCode(HttpStatus.SUCCESS);
        result.setMsg("查询成功");
        result.setRows(list1);

        return result;
    }
}
